#include"process.h"


#define TARGET_SIZE 1024*1024 //1MB

#define DSIZE 1024*10

//结合场景来谈，v2.1
//void download()
//{
//	int target = TARGET_SIZE;
//	int total = 0;
//
//	while(total < target)
//	{
//		usleep(STIME);//用简单的休眠时间，模拟本轮下载花费的时间
//		total += DSIZE;
//		process_v2(total*100/target);
//	}
//	printf("\n");
//}
//

void download(callback_t cb)
{
	int testcnt = 10;
	int target = TARGET_SIZE;
	int total = 0;

	while(total <= target)
	{
		usleep(STIME);//用简单的休眠时间，模拟本轮下载花费的时间
		total += DSIZE;
		double rate = total*100.0/target;
		if(rate > 50.0 && testcnt) 
		{
			total = target/2;
			testcnt--;
		}
		cb(rate);//回调函数
	}
	cb(MAX_RATE);
	printf("\n");
}
//下载的软件
int main()
{
	download(process_v3);
	return 0;
}

